(function(window) {
    "user strict";
    var pay = function() {

    }
    pay.prototype = {
        fnWxPay: function(pParam, pCallBack) {
            var _wxPay = api.require('wxPay');
            _wxPay.payOrder({
                apiKey: pParam.apiKey,
                orderId: pParam.orderId,
                mchId: pParam.mchId,
                nonceStr: pParam.nonceStr,
                timeStamp: pParam.timeStamp,
                package: pParam.package,
                sign: pParam.sign
            }, function(ret, err){
                 if (ret.status) {
                    pCallBack();
                 }else{
                   if (err.code && '-2' == err.code) {
                       api.toast({
                           msg: '取消支付',
                           duration: 2000,
                           location: 'bottom'
                       });
                   } else {
                       api.toast({
                           msg: '支付失败',
                           duration: 2000,
                           location: 'bottom'
                       });
                   }
                 }
            });
        },
        fnAliPayPlus: function(pOrderId, pCallBack) {
            var _aliPayPlus = api.require("aliPayPlus");
            _aliPayPlus.payOrder({
                orderInfo: pOrderId
            }, function(ret, err) {
                if (ret) {
                    if (ret.code) {
                        var tCode = ret.code;
                        var tMsg = '支付失败';
                        switch (tCode) {
                            case '9000':
                                tMsg = '支付成功';
                                pCallBack();
                                break;
                            case 9000:
                                tMsg = '支付成功';
                                pCallBack();
                                break;
                            case '8000':
                                tMsg = '正在处理中,请查询商户订单列表中订单的支付状态'
                                break;
                            case 8000:
                                tMsg = '正在处理中,请查询商户订单列表中订单的支付状态'
                                break;
                            case '4000':
                                tMsg = '支付失败'
                                break;
                            case 4000:
                                tMsg = '支付失败'
                                break;
                            case '5000':
                                tMsg = '重复请求'
                                break;
                            case 5000:
                                tMsg = '重复请求'
                                break;
                            case '6001':
                                tMsg = '取消支付'
                                break;
                            case 6001:
                                tMsg = '取消支付'
                                break;
                            case '6002':
                                tMsg = '网络连接出错'
                                break;
                            case 6002:
                                tMsg = '网络连接出错'
                                break;
                            case '6004':
                                tMsg = '支付结果未知，请查询商户订单列表中订单的支付状态'
                                break;
                            case 6004:
                                tMsg = '支付结果未知，请查询商户订单列表中订单的支付状态'
                                break;
                        }
                        api.toast({
                            msg: tMsg,
                            duration: 2000,
                            location: 'bottom'
                        });
                    } else {
                        api.toast({
                            msg: '支付失败',
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                } else {
                    api.toast({
                        msg: '支付失败',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
        }
    }
    window.pay = pay;
})(window)
